<?php
/**
*公共配置
**/
header("Content-type:text/html;charset=utf-8");
    date_default_timezone_set('PRC');
    ini_set("display_errors", "On");
    error_reporting(E_ALL | E_STRICT);
require_once(dirname(__FILE__).'/../../include/rnpdo.class.php');
//创建礼品列表
$res = $rnpdo->RnQuery("
CREATE TABLE IF NOT EXISTS `sn_app_card_20190301_studrites` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(32) NOT NULL COMMENT '礼品名称',
  `type` tinyint(2) unsigned NOT NULL DEFAULT '0' COMMENT '充值类型0.卡密提取1.手机充值2.游戏充值',
  `prize` int(6) unsigned NOT NULL DEFAULT '0' COMMENT '礼品价值',
  `num` int(6) unsigned NOT NULL DEFAULT '0' COMMENT '礼品数量',
  `version` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '版本号',
  PRIMARY KEY (`id`),
  KEY `version` (`version`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COMMENT='学子礼品库' AUTO_INCREMENT=7 ;");

echo empty($res['errmsg']) ? '创建配置表失败<br>' : '创建配置表成功<br>';
if(!empty($res['errmsg']))
{
  $res = $rnpdo->RnQuery("INSERT INTO `sn_app_card_20190301_studrites` (`id`, `name`, `type`, `prize`, `num`, `version`) VALUES
(1, '腾讯视频会员（1个月直充）', 2, 20, 749, 1),
(2, 'QQ绿钻（1个月直充）', 2, 15, 1499, 1),
(3, 'Q币直充', 2, 20, 2248, 2),
(4, '滴滴快车电子券（卡密）', 0, 20, 1487, 13),
(5, '手机话费（三网直充）', 1, 20, 1483, 17),
(6, '爱奇艺视频会员（1个月直充）', 2, 20, 749, 1);");
  echo empty($res['errmsg']) ? '礼品表数据添加失败<br>' : '礼品表数据添加成功<br>';
}
// 创建领取礼品记录表
$res = $rnpdo->RnQuery("CREATE TABLE IF NOT EXISTS `sn_app_card_20190301_rites_log` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `userid` varchar(32) NOT NULL COMMENT '用户标识',
  `goods_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商品id',
  `goodstype` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '0.卡密提取1.话费充值2.游戏',
  `game_userid` varchar(32) NOT NULL COMMENT '手机号/账号',
  `sporder_id` varchar(32) NOT NULL COMMENT '订单号',
  `cardnum` int(6) unsigned NOT NULL DEFAULT '0' COMMENT '充值金额',
  `cardid` varchar(20) NOT NULL COMMENT '欧飞商品编号',
  `sporder_time` varchar(32) NOT NULL COMMENT '充值时间',
  `orderid` varchar(32) NOT NULL COMMENT '欧飞流水号',
  `addtime` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '添加时间戳',
  `add_date` date NOT NULL DEFAULT '0000-00-00' COMMENT '添加日期',
  `retcode` int(6) NOT NULL DEFAULT '0' COMMENT '业务状态码',
  `game_state` tinyint(3) NOT NULL DEFAULT '0' COMMENT '0.充值中1.成功',
  `ordersuccesstime` varchar(32) NOT NULL COMMENT '充值成功时间',
  `err_msg` varchar(255) NOT NULL COMMENT '充值结果说明',
  `res` text NOT NULL COMMENT '充值结果',
  PRIMARY KEY (`id`),
  UNIQUE KEY `sporder_id` (`sporder_id`),
  KEY `userid` (`userid`,`game_userid`),
  KEY `orderid` (`orderid`),
  KEY `goods_id` (`goods_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COMMENT='用户领取礼品记录表' AUTO_INCREMENT=20 ;");
echo empty($res['errmsg']) ? '创建领取礼品记录表失败<br>' : '创建领取礼品记录表成功<br>';